import datetime
from shared.graph_client import GraphClient

class AuditLogManager:
    def __init__(self, graph_client: GraphClient):
        self.client = graph_client
        
    def fetch_audit_logs(self, start_time: datetime.datetime, end_time: datetime.datetime):
        """获取审计日志"""
        params = {
            "$filter": f"activityDateTime ge {start_time.isoformat()}Z "
                      f"and activityDateTime le {end_time.isoformat()}Z"
        }
        return list(self.client.paginate("auditLogs/signIns", params=params))
    
    def archive_logs(self, logs: list):
        """归档日志到存储"""
        log_data = json.dumps(logs).encode()
        timestamp = datetime.datetime.utcnow().strftime("%Y%m%d%H%M")
        return self.storage.store(
            f"audit_logs/{timestamp}.json.zst",
            self._process_data(log_data)
        )